#!/usr/bin/node

const http = require('http'),
      log  = require('util').debuglog('dev'),
      fs   = require('fs');


http.createServer((req,res) => {
  log(`${req.method} ${req.url} HTTP/${req.httpVersion}`);
  log(req.headers);
  log(process.pid);
  log();

  //let fileName = __dirname + req.url,
      //fileData = fs.readFileSync(fileName);

  //res.end(fileData);
  
  let file = __dirname + req.url;
  fs.readFile(file,(err,data) => {
    if(err){
      log(err.message);
      res.statusCode = 404;
      res.end(err.message);
    }else{
      res.end(data);
    }
  });
}).listen(8080);

